<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\paginator\driver\Bootstrap;
use app\common\services\SysmessageService;

use think\Cache;

/**
 * 消息接口
 */
class Sysmessage extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    /**
     * 消息列表
     */
    public function list()
    {   
        $data['user_id'] = $this->auth->id;
        $page_info = $this->getPerPage();
        $cache_key = 'sysmessage_lists:'.md5(serialize($data).serialize($page_info));
        $result    = Cache::get($cache_key);
        if($result && $this->__flush_cache === false){
        
        }else{
            $result =  SysmessageService::list($data, $page_info);
            Cache::set($cache_key, $result, $this->getTtl());
        }
        return $this->success('success',$result);
    }
    

    /**
     * 消息详情
     */
    public function info(){

        $id = $this->request->param('id');
        if (empty($id)) {
            return $this->error('参数错误');
        }

        $cache_key = 'sysmessage_info:_'.$id;
        $cache = Cache::get($cache_key);
        if($cache && $this->__flush_cache === false){
            return $this->success($cache);
        }

        $info  = SysmessageService::info($id);
        Cache::set($cache_key, $info, $this->getTtl());
        return $this->success($info);
    }
}
